package com.newMedical.medicine.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.newMedical.common.annotation.Log;
import com.newMedical.common.core.controller.BaseController;
import com.newMedical.common.core.domain.AjaxResult;
import com.newMedical.common.enums.BusinessType;
import com.newMedical.medicine.domain.YpPrescription;
import com.newMedical.medicine.service.IYpPrescriptionService;
import com.newMedical.common.utils.poi.ExcelUtil;
import com.newMedical.common.core.page.TableDataInfo;

/**
 * 处方Controller
 * 
 * @author zhou
 * @date 2021-12-03
 */
@RestController
@RequestMapping("/medicine/prescription")
public class YpPrescriptionController extends BaseController
{
    @Autowired
    private IYpPrescriptionService ypPrescriptionService;

    /**
     * 查询处方列表
     */
    @PreAuthorize("@ss.hasPermi('medicine:prescription:list')")
    @GetMapping("/list")
    public TableDataInfo list(YpPrescription ypPrescription)
    {
        startPage();
        List<YpPrescription> list = ypPrescriptionService.selectYpPrescriptionList(ypPrescription);
        return getDataTable(list);
    }

    /**
     * 导出处方列表
     */
    @PreAuthorize("@ss.hasPermi('medicine:prescription:export')")
    @Log(title = "处方", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YpPrescription ypPrescription)
    {
        List<YpPrescription> list = ypPrescriptionService.selectYpPrescriptionList(ypPrescription);
        ExcelUtil<YpPrescription> util = new ExcelUtil<YpPrescription>(YpPrescription.class);
        util.exportExcel(response, list, "处方数据");
    }

    /**
     * 获取处方详细信息
     */
    @PreAuthorize("@ss.hasPermi('medicine:prescription:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ypPrescriptionService.selectYpPrescriptionById(id));
    }

    /**
     * 新增处方
     */
    @PreAuthorize("@ss.hasPermi('medicine:prescription:add')")
    @Log(title = "处方", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YpPrescription ypPrescription)
    {
        return toAjax(ypPrescriptionService.insertYpPrescription(ypPrescription));
    }

    /**
     * 修改处方
     */
    @PreAuthorize("@ss.hasPermi('medicine:prescription:edit')")
    @Log(title = "处方", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YpPrescription ypPrescription)
    {
        return toAjax(ypPrescriptionService.updateYpPrescription(ypPrescription));
    }

    /**
     * 删除处方
     */
    @PreAuthorize("@ss.hasPermi('medicine:prescription:remove')")
    @Log(title = "处方", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ypPrescriptionService.deleteYpPrescriptionByIds(ids));
    }
}
